﻿#include "OperSpectrogramResult.h"

#include "GUIFrame/MainWindow.h"
#include "GUIFrame/CentralWidget.h"
#include "GUIWidget/PreWindow3D.h"
#include "GUIDialog/GUIPostDialog/GUISpectrogramResultDialog.h"
#include "OperatorsInterface/GraphPostEventOperator.h"

#include "FITK_Kernel/FITKCore/FITKAbstractDataManager.hpp"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsDiscModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAcousticsSEAModel.h"
#include "FITK_Component/FITKAcousticsModel/FITKAbstractSEASubSys.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbstractSpectra.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKSpectraPressure.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKSpectraVelocity.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKSpectraAlgorithm.h"
#include "FITK_Component/FITKAcousticsPostData/FITKAcousticsPostData.h"
#include "FITK_Component/FITKAcousticsPostData/FITKAcousticsContourPlotData.h"
#include "FITK_Component/FITKAcousticsPostData/FITKAcousticsHDF5AttributeObject.hpp"
#include "FITK_Component/FITKAcousticsPostData/FITKAcousticsHDF5Constants.h"
#include "FITK_Component/FITKAcousticsPostData/FITKAcousticsHDF5DataSet.hpp"
#include "FITK_Component/FITKAcousticsPostData/FITKAcousticsHDF5Frequencies.h"
#include "FITK_Component/FITKAcousticsPostData/FITKAcousticsHDF5LoadCase.h"
#include "FITK_Component/FITKRenderWindowVTK/FITKGraph3DWindowVTK.h"

#include <qmath.h>

namespace GUIOper
{

    bool OperSpectrogramResult::execGUI()
    {
        //获取当前3D窗口
        GUI::MainWindow * mainWindow = dynamic_cast<GUI::MainWindow *>(FITKAPP->getGlobalData()->getMainWindow());
        if (!mainWindow) return false;
        GUI::CentralWidget* centralWidget = mainWindow->getCentralWidget();
        if (!centralWidget) return false;
        GUI::GraphArea* graphArea = centralWidget->getGraphArea();
        if (!graphArea) return false;
        GUI::PreWindow3D* widget3D = graphArea->getCurrentWindow<GUI::PreWindow3D>();
        if (!widget3D) return false;
        //获取当前的3D窗口的云图配置数据
        Acoustics::FITKAcousticsContourPlotData* contourPlotData = this->getContourPlotDataBy3DWidget(widget3D);
        if (!contourPlotData) return false;
        GUI::GUISpectrogramResultDialog* dialog = new GUI::GUISpectrogramResultDialog(contourPlotData, this, widget3D->getRenderWindow());
        dialog->show();
        return false;
    }

    bool OperSpectrogramResult::execProfession()
    {
        //临时
        return false;
    }

    Acoustics::FITKAcousticsContourPlotData* OperSpectrogramResult::getContourPlotDataBy3DWidget(GUI::PreWindow3D* widget3D)
    {
        if (!widget3D) return nullptr;
        //获取后处理数据
        Acoustics::FITKAcousticsPostData* postData = FITKAPP->getGlobalData()->getPostData<Acoustics::FITKAcousticsPostData>();
        if (nullptr == postData) return nullptr;
        //获取云图管理器
        auto contourPlotManager = postData->getContourPlotDataManager();
        if (nullptr == contourPlotManager) return nullptr;
        //获取当前窗口的云图数据
        QString widget3DName = QString("widget3D_%1").arg(widget3D->getGUIObjectID());
        Acoustics::FITKAcousticsContourPlotData* plotData = dynamic_cast<Acoustics::FITKAcousticsContourPlotData*>(contourPlotManager->getDataByName(widget3DName));
        if (nullptr == plotData)
        {
            //当前窗口的云图不存在就创建
            plotData = new Acoustics::FITKAcousticsContourPlotData();
            plotData->setDataObjectName(widget3DName);
            contourPlotManager->appendDataObj(plotData);
        }
        return plotData;
    }
}
